package com.zyh.controller;

import com.zyh.entity.NACheck;
import com.zyh.entity.Student;
import com.zyh.entity.Users;
import com.zyh.service.NACheckService;
import com.zyh.service.StudentService;
import com.zyh.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@Controller
public class InspectorController {
    @Resource
    UserService userService;
    @Resource
    StudentService studentService;
    @Resource
    NACheckService naCheckService;

    @RequestMapping("/IdoSave")
    public String IdoSave(@RequestParam("sno")String sno, @RequestParam("healthy")String healthy , @RequestParam("users.username") String username){
        Student student=studentService.findStudentBySno(Integer.parseInt(sno));
        Users users= userService.findByUserName(username);
        NACheck naCheck=new NACheck();

        Date entime = new Date();
        naCheck.setEnterTime(entime);
        naCheck.setSno(student.getSno());
        naCheck.setSname(student.getName());
        naCheck.setIname(users.getName());
        naCheck.setUsername(users.getUsername());
        naCheck.setResult(healthy);
        student.setHealthy(healthy);
        naCheckService.save(naCheck);
        studentService.save(student);

        return "InspectorView/success";
    }

}
